
package com.joysuch.wwyt.core.service;

import com.joysuch.wwyt.core.bean.*;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.entity.BaseMenuFunction;
import com.joysuch.wwyt.core.security.ShiroUser;
import javafx.util.Pair;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;

public interface AuthorityService {

    List<AuthorityBean> queryAuthorityByUserId(Long userId, boolean superAdmin);

    /**
     * 根据roleId查询权限
     *
     * @param roleId
     * @return
     */
    public List<AuthorityBean> queryForEditByRoleId(Long roleId);

    /**
     * 根据用户获取授权菜单列表
     *
     * @param userId
     * @param superAdmin
     * @return
     */
    List<BaseMenuFunction> queryMenuFunctionByUserId(Long userId, boolean superAdmin);

    @Transactional
    List<SimpleSelectListBean> queryMenuListByUserId(Long userId, boolean superAdmin);

    List<SimpleSelectListBean> selectSystemList();

    /**
     * 查询顶层菜单
     *
     * @return
     */
    public List<AuthorityBean> queryForTopMenu();

    /**
     * 查询用户权限字符串
     *
     * @param userId
     * @return
     */
    public Pair<Set<String>, Set<String>> queryUserPerms(Long userId);

    /**
     * 更新权限。
     * 如果userId不为空，则此权限为用户授权。更新用户授权表。
     * 如果userId为空，jobId不为空，更新岗位权限表。
     * userId，jobId同时为空，则报异常
     *
     * @param jobId
     *            岗位iD
     * @param userId
     *            用户ID
     * @param list
     *            完整的权限列表
     */
    public void updateAuthority(Long jobId, Long userId, List<AuthorityBean> list);

    /**
     * 添加菜单
     *
     * @param bean
     */
    public void addOrUpdateMenu(BaseMenuFunctionEditBean bean);

    /**
     * 根据名称查询菜单
     *
     * @param name
     *            名称
     * @param exactMatch
     *            严格匹配
     * @return 菜单列表
     */
    public List<BaseMenuFunctionEditBean> queryMenuByName(String name, boolean exactMatch);

    public List<SimpleSelectListBean> queryForUserRoleList(Long userId);

    public void updateUserRoles(UserAssignRoleBean bean);

    List<DashboardMenuBean> queryDashboardList();

    List<AuthorityBean> parse(Collection<BaseMenuFunction> functions);

    List<DashboardMenuBean> convertMenuData(List<AuthorityBean> authList);

    void roleUpdateUsers(BaseRoleAddUserBean roleAddUserBean);

    ResultBean roleUserList(BaseUserRoleListSearchBean bean);

    /**
     * 根据查询条件获取全部用户id
     * @param bean
     * @return
     */
    ResultBean newRoleUserList(BaseUserRoleListSearchBean bean);

    ResultBean roleUserListAll(Long roleId);

    List<BaseMenuFunction> findAppMenuList(Long userId, boolean superAdmin);

    /**
     * 按条件踢出在线用户
     *
     * @param predicate
     */
    List<ShiroUser> kickOutUser(Predicate<ShiroUser> predicate);

}
